package com.zrc.plugin;

import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;

public class PluginActivity extends BaseActivity {
    private TestReceiver testReceiver = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //LogUtil.e(TAG+"-->"+"onCreate(Bundle savedInstanceState)");

        setContentView(R.layout.activity_plugin);

        //跳转插件界面
        findViewById(R.id.tv1).setOnClickListener(view -> {
            Intent intent = new Intent(activity, TestActivity.class);
            intent.putExtra("data", "我是上个界面穿过来的数据...");
            startActivity(intent);
        });

        //跳转宿主界面
        findViewById(R.id.tv2).setOnClickListener(view -> {
            Intent intent = new Intent();
            intent.setClassName(activity, "com.cocos.game.AppActivity");
            startOutActivity(intent);
        });

        //启动宿主传过来的服务
        findViewById(R.id.tv3).setOnClickListener(view -> {
            Intent intent = new Intent(activity, TestService.class);
            startService(intent);
        });

        //注册宿主传过来的广播
        findViewById(R.id.tv4).setOnClickListener(view -> {
            IntentFilter intentFilter = new IntentFilter();
            intentFilter.addAction("wangzs");
            testReceiver = new TestReceiver();
            registerReceiver(new TestReceiver(), intentFilter);
        });

        //注销宿主传过来的广播
        findViewById(R.id.tv5).setOnClickListener(view -> {
            unregisterReceiver(testReceiver);
        });

        //发送广播
        findViewById(R.id.tv6).setOnClickListener(view -> {
            Intent intent = new Intent();
            intent.setAction("wangzs");
            intent.putExtra("wangzs", "ssssssssssss");
            sendBroadcast(intent);
        });
    }
}